package com.tedu.review.test;

import java.util.Objects;
import java.util.concurrent.Callable;

/**
 * equals方法
 * 测试类：China类---属性：city  county
 */
public class Object判断 {
    public static void main(String[] args) {
        //创建两个china类
        China c1=new China();
        c1.city="唐山";
        c1.county="曹妃甸";
        //System.out.println(c1);
        China c2=new China();
        c2.city="唐山";
        c2.county="曹妃甸";
        //System.out.println(c2);
        //equals()默认Object类提供 比 地址值---- 逻辑修改：市跟县是否相等
        System.out.println(c1.equals(c2));
    }
}
class China{
    public String city;   //市
    public String county; //县
    //重写equals方法：判断China中市和县是否相等
    public boolean equals(Object o) {
        //1.将Object超类强转为china：向下造型
        China china = (China) o;
        //2.China对象到调属性：city county
        boolean c = this.city.equals(china.city);
        //当前China对象的city属性与拿到China参数中city对比
        boolean y = this.county.equals(china.county);
        //两两对比之后，全部都正确 弹出true  否则false
        return c && y;
    }
}